package com.guaika.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.dto.DishDto;
import com.guaika.reggie.entity.Category;
import com.guaika.reggie.entity.Dish;
import com.guaika.reggie.entity.DishFlavor;
import com.guaika.reggie.service.CategoryService;
import com.guaika.reggie.service.DishFlavorService;
import com.guaika.reggie.service.DishServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author GuaiKa
 * 菜品控制层
 */
@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishServices dishServices;

    /**
     * 菜品保存
     * @param dishDto
     * @return
     */
    @PostMapping
    public ResultMessage<String> save(@RequestBody DishDto dishDto){
        dishServices.saveDishAndDishFlavor(dishDto);
        return ResultMessage.success(StringChars.SAVE_MESSAGE.getStr());
    }

    /**
     * 起售停售
     * @param status
     * @param ids
     * @return
     */

    @PostMapping("/status/{status}")
    public ResultMessage<String> statusUpdate(@PathVariable("status") Integer status,Long[] ids){
        return dishServices.statusUpdate(status,ids);
    }
    /***
     * 根据分类id查询菜品信息
     * @param dish
     * @return
     */
    @GetMapping("/list")
    public ResultMessage<List<DishDto>> list(Dish dish){
        return dishServices.dishlist(dish);
    }


    @GetMapping("/page")
    public ResultMessage<Page> page(int page,int pageSize,String name){
        return dishServices.dishPage(page, pageSize, name);
    }

    /***
     * 根据id获取菜品信息与口味信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultMessage<DishDto> getDishDto(@PathVariable Long id){
        return ResultMessage.success(dishServices.getByIdWidthDish(id));
    }

    @PutMapping
    public ResultMessage<String> update(@RequestBody DishDto dishDto){
        dishServices.updateWidthDishDto(dishDto);
        return ResultMessage.success(StringChars.UPDATE_SUCCESS.getStr());
    }
}
